<html>
    <head>
        <style>
            body {
                padding: 0;
                margin: 0;
            }

            #box {
                width: 100px;
                height: 100px;
                background-color: #00cc88;
            }

            #child {
                width: 50px;
                height: 50px;
                background-color: #0077ff;
            }

            #box.b {
                height: 200px;
                position: absolute;
                top: 100px;
                left: 200px;
                padding: 20px;
            }

            #trigger-overflow {
                width: 1px;
                height: 1px;
                position: absolute;
                top: 2000px;
                left: 2000px;
            }

            [data-layout-correct="false"] {
                background: #dd1144 !important;
                opacity: 0.5;
            }
        </style>
    </head>
    <body>
        <div id="box"></div>
        <div id="trigger-overflow"></div>

        <script type="module" src="/src/imports/projection.js"></script>
        <script type="module" src="/src/imports/script-assert.js"></script>
        <script type="module" src="/src/imports/script-undo.js"></script>
        <script type="module">
            const { createNode } = window.Undo
            const { matchViewportBox } = window.Assert
            const { frame, HTMLProjectionNode } = window.Projection

            const box = document.getElementById("box")
            const boxProjection = createNode(box)

            const boxOrigin = box.getBoundingClientRect()
            const a = document.createElement("div")
            a.id = "child"

            // Render phase
            const aProjection = createNode(
                a,
                boxProjection,
                { layout: true },
                "a"
            )
            const bProjection = new HTMLProjectionNode({}, boxProjection)

            // Snapshot
            boxProjection.willUpdate()

            // Commit
            box.appendChild(a)
            box.classList.add("b")

            // First layout effect
            boxProjection.root.didUpdate()

            // A/B mounts
            aProjection.mount(a)

            frame.postRender(() => {
                matchViewportBox(box, boxOrigin)
                matchViewportBox(a, {
                    bottom: 70,
                    left: 20,
                    right: 70,
                    top: 20,
                })
            })
        </script>
    </body>
</html>
